<?php

  require_once __CFG_PATH_LIBS.__CFG_PATH_CORE."menu.inc";

  $WorkTableKeyVarName = $CONFIG['keyVarPrefix'].$WorkTableKeyFieldName;
  $WorkTable = &$_SQL_TABLE[$GlobPart];

  //$TabFields['a'] = getFieldNamesWithLangs($_SQL_TABLE['article'], array('title'));
  $TabFields['mb'] = getFieldNamesWithLangs($_SQL_TABLE['menu_block'], array('title'));
  $TabFields['m'] = getFieldNamesWithLangs($WorkTable, array('title'));

  $MenuBlocksSelect = array_kv(getTableAsArray($_SQL_TABLE['menu_block'], $TabFields['mb']['title'], array(), '', 'id,'.$TabFields['mb']['title']), $TabFields['mb']['title'], 'id');

  if($_REQUEST[mode] == $GlobPart)
  {
    $PageTitle = '$language["admin"]["frontMenu"]." :: ".$Item["'.$TabFields['m']['title'].'"];';
    $RowItem = getRowByField($WorkTable, $WorkTableKeyFieldName, $_GET[$WorkTableKeyVarName]);
    //$MenuBlocksSelected = array_kv(getTableAsArray($_SQL_TABLE['menu_block'], 'id', array("id IN ('".str_replace($CONFIG['AdminListInRowDelim'], "','", $RowItem['menu_block'])."')"), '', 'id,'.$TabFields['mb']['title']), $TabFields['mb']['title'], 'id');

    $FrontMenu = FrontMenu::getInstance();

    $TypesSelect = $FrontMenu->getMenuModules();
    $ParamsSelect = $FrontMenu->getMenuModulesParams();
    $CurrVals = $FrontMenu->setMenuParamsArray($RowItem['params']);
    if($CurrVals['module'])
    {
      $link = array($TypesSelect[$CurrVals['module']].' -> '.$ParamsSelect[$CurrVals['module']][$CurrVals['params']]);
    }
    else
    {      $link = array($language['admin']['none']);
    }
  }
  else
  {
  	$PageTitle = '$language["admin"]["frontMenu"];';
  	$AloneMode = $GlobPart;

  	$Query['FromTables'] = 	$WorkTable." m
  							LEFT JOIN ".$_SQL_TABLE['menu_block']." mb ON mb.id = m.menu_block";
  	$Query['Fields'] = "m.*,mb.".$TabFields['mb']['title']." AS menu_block";
  	$Query['TabOrder'] = "m.";
  	$Query['Where'] = "";
  	$Query['GroupBy'] = "";

    $EnableFilter = true;

  	$listInfo['where']['menu_block'] = array(
  								'simple' => 'y',
  								'SQLField' => "FIND_IN_SET('".$_REQUEST['menu_block']."', m.menu_block) > 0",
  								'type' => 'select',
  								'title' => $language['admin']['frontMenuBlock'],
  								'values' => array('' => ucfirst($language['admin']['all'])) + $MenuBlocksSelect,
  								'JSact' => '',
  								);
    require_once __CFG_PATH_CODE_ADMIN."admin.filter.inc";
  }


  $ConfLangArr = array(
				'title_' => array(
								'type' => 'input',
								'title' => $language['admin']['title'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST,
								'useInList' => $CONFIG['useInListSort'],
								'required' => $CONFIG['AdminReqPatAll'],
								'maxlength' => '80',
								'size' => '60',
								));

  $GeneratedLangArr = getAdminConfigArrayWithLangs($ConfLangArr, $SITE_LANGS);


  $_SQL_TABLE_FIELDS[$GlobPart] = $GeneratedLangArr + array(

				'menu_block' => array(
                                'type' => 'select',
								'title' => $language['admin']['frontMenuBlock'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['menu_block'],
								'useInList' => $CONFIG['useInListSort'],
								'required' => $CONFIG['AdminReqPatAll'],
								'values' => $MenuBlocksSelect,
								'orderby' => $TabFields['mb']['title'].',m.'.$TabFields['m']['title'],
								'tabord' => 'mb.',
								),

				'params' => array(

								'type' => 'relation_field',
								'title' => $language['admin']['params'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['params'],
								//'required' => $CONFIG['AdminReqPatAll'],
								'listValues' => $link,
								'listToField' => 'y',
								'size' => '20',
								'width' => '500',
								'height' => '500',
								'maxlength' => '20',
								'other' => 'disabled',
								'openLink' => '',
								'openLinkParams' => array(
													'mode' => 'get_values',
													'elemid' => 'params',
													'tsk' => 'get_menu_params',
													'cntonly' => 'y',
													'resize_win' => 'y',
													'currval' => '"+encodeURIComponent(document.getElementById("params").value)+"',
										),
								),

				'outerlink' => array(
								'type' => 'input',
								'title' => $language['admin']['outerLink'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['outerlink'],
								'useInList' => $CONFIG['useInListSort'],
								'allowEmpty' => 'y',
								'maxlength' => '255',
								'size' => '60',
								),

				'position' => array(
								'type' => 'input',
								'title' => $language['admin']['position'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['position'],
								'useInList' => $CONFIG['useInListSort'],
								'allowEmpty' => 'y',
								'inListEdit' => 'list_input',
								'useInListEdit' => 'y',
								'size' => '3',
								'maxlength' => '3',
								),

				'active' => array(
								'type' => 'select_link',
								'title' => $language['admin']['status'],
								'formid' => $CONFIG['activeFormName'],
								'addVariable' => 'y',
								'useInList' => $CONFIG['useInListSort'],
								'inListEdit' => 'select_link',
								'noUseInEdit' => 'y',
								'values' => array(
											'y' => array(
													'title' => $language['admin']['active'],
													'className' => 'active',
													'formFields' => array(
																	'act' => 'status',
																	'varvalue' => 'n',
																	'varname' => 'active',
																	getKeyVarName() => '{$Item.$WorkTableKeyFieldName}',
													),
											),
											'n' => array(
													'title' => $language['admin']['inactive'],
													'className' => 'inactive',
													'formFields' => array(
																	'act' => 'status',
																	'varvalue' => 'y',
																	'varname' => 'active',
																	getKeyVarName() => '{$Item.$WorkTableKeyFieldName}',
													),
											),
								),
				),


				'date' => array(
								'type' => 'value',
								'title' => $language['admin']['date'],
								'addVariable' => 'NOW()',
								'addVarType' => $CONFIG['VarTypeSQLFunction'],
								'useInList' => $CONFIG['useInListSort'],
								'useInListEdit' => 'y',
								),

  );
  $_SQL_TABLE_EDIT_FORMS[$GlobPart] = array('active');


?>